package org.cuit.epoch.seon.top;

import java.util.Scanner;

// 主程序
public class FileManagementSystem {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        FileSystemManager fsm = new FileSystemManager();
        fsm.showHelp();

        String command;
        while (true) {
            System.out.print("> ");
            command = scanner.nextLine();
            String[] parts = command.split(" ");
            switch (parts[0]) {
                case "ls":
                    fsm.showCurrentDirectory();
                    break;
                case "mkfile":
                    if (parts.length == 3) {
                        String name = parts[1];
                        int size = Integer.parseInt(parts[2]);
                        fsm.createFile(name, size);
                    } else {
                        System.out.println("Usage: mkfile <name> <size>");
                    }
                    break;
                case "mkdir":
                    if (parts.length == 2) {
                        fsm.createDirectory(parts[1]);
                    } else {
                        System.out.println("Usage: mkdir <name>");
                    }
                    break;
                case "rm":
                    if (parts.length == 2) {
                        fsm.delete(parts[1]);
                    } else {
                        System.out.println("Usage: rm <name>");
                    }
                    break;
                case "rename":
                    if (parts.length == 3) {
                        fsm.rename(parts[1], parts[2]);
                    } else {
                        System.out.println("Usage: rename <old> <new>");
                    }
                    break;
                case "copy":
                    if (parts.length == 2) {
                        fsm.copy(parts[1]);
                    } else {
                        System.out.println("Usage: copy <name>");
                    }
                    break;
                case "paste":
                    fsm.paste();
                    break;
                case "cd":
                    if (parts.length == 2) {
                        fsm.changeDirectory(parts[1]);
                    } else {
                        System.out.println("Usage: cd <name>");
                    }
                    break;
                case "exit":
                    scanner.close();
                    return;
                default:
                    System.out.println("Unknown command. Type 'help' for a list of commands.");
            }
        }
    }
}